In [3]:
import requests

These are the search queries for the Spotify Web API


In [4]:
response = requests.get('https://api.spotify.com/v1/search?query=Lil&type=artist&limit=50&market=US')
Lil_data = response.json()

In [5]:
Lil_data.keys()


Out[5]:
dict_keys(['artists'])

In [6]:
Lil_data['artists'].keys()


Out[6]:
dict_keys(['previous', 'items', 'total', 'href', 'offset', 'next', 'limit'])

1) With "Lil Wayne" and "Lil Kim" there are a lot of "Lil" musicians. Do a search and print a list of 50 that are playable in the USA (or the country of your choice), along with their popularity score.


In [7]:
Lil_artists = Lil_data['artists']['items']
for artist in Lil_artists:
    print(artist['name'], artist['popularity'])


Lil Wayne 86
Lil Yachty 72
Lil Uzi Vert 72
Lil Dicky 68
Boosie Badazz 67
Lil Jon 72
King Lil G 61
Lil Durk 60
Lil Jon & The East Side Boyz 60
Lil Bibby 54
G Herbo 53
Lil Rob 50
Lil Reese 50
Lil Keke 48
Bow Wow 57
Lil Scrappy 48
Lil Wyte 50
Lil Blood 45
Lil Snupe 45
Lil Mama 45
Lil B 44
Lil' Kim 62
Lil Cuete 40
Lil Phat 39
Lil Debbie 43
Lil Twist 39
Lil Trill 37
Lil Twon 38
Lil AJ 37
Lil Lonnie 37
Lil Boom 35
Lil Goofy 35
Mr. Lil One 36
Lil Haiti 36
Lil Flash 38
Lil Kesh 39
Lil Cray 35
Lil Silva 43
Lil Rue 34
Lil Eddie 41
Lil Yase 33
Lil Wayne, DJ Drama 35
Lil Suzy 34
Lil Mouse 34
Lil C 33
Lil Rick 39
Lil June 32
Lil E 34
Lil Fate 34
Lil' Flip 49

2 a) What genres are most represented in the search results?

Finding all the genres and combining into one list.


In [8]:
Lil_artists = Lil_data['artists']['items']

for artist in Lil_artists:
    print(artist['name'], artist['popularity'])
    #joining
    if len(artist['genres']) == 0:
        print("No genres listed")
    else:
        genres = ", ".join(artist['genres'])
        print("Genres: ", genres)


Lil Wayne 86
Genres:  dirty south rap, pop rap, southern hip hop, trap music
Lil Yachty 72
No genres listed
Lil Uzi Vert 72
No genres listed
Lil Dicky 68
No genres listed
Boosie Badazz 67
No genres listed
Lil Jon 72
Genres:  crunk, dirty south rap, southern hip hop
King Lil G 61
No genres listed
Lil Durk 60
No genres listed
Lil Jon & The East Side Boyz 60
No genres listed
Lil Bibby 54
No genres listed
G Herbo 53
No genres listed
Lil Rob 50
Genres:  chicano rap, latin hip hop
Lil Reese 50
No genres listed
Lil Keke 48
No genres listed
Bow Wow 57
Genres:  hip pop, pop rap
Lil Scrappy 48
Genres:  crunk, dirty south rap, southern hip hop, trap music
Lil Wyte 50
Genres:  juggalo
Lil Blood 45
No genres listed
Lil Snupe 45
No genres listed
Lil Mama 45
Genres:  hip pop
Lil B 44
No genres listed
Lil' Kim 62
Genres:  hip pop
Lil Cuete 40
Genres:  chicano rap
Lil Phat 39
No genres listed
Lil Debbie 43
No genres listed
Lil Twist 39
Genres:  jerk
Lil Trill 37
Genres:  deep trap
Lil Twon 38
No genres listed
Lil AJ 37
No genres listed
Lil Lonnie 37
No genres listed
Lil Boom 35
No genres listed
Lil Goofy 35
No genres listed
Mr. Lil One 36
Genres:  chicano rap
Lil Haiti 36
No genres listed
Lil Flash 38
No genres listed
Lil Kesh 39
No genres listed
Lil Cray 35
No genres listed
Lil Silva 43
No genres listed
Lil Rue 34
No genres listed
Lil Eddie 41
No genres listed
Lil Yase 33
No genres listed
Lil Wayne, DJ Drama 35
No genres listed
Lil Suzy 34
Genres:  freestyle
Lil Mouse 34
No genres listed
Lil C 33
No genres listed
Lil Rick 39
Genres:  soca
Lil June 32
No genres listed
Lil E 34
No genres listed
Lil Fate 34
No genres listed
Lil' Flip 49
Genres:  crunk, dirty south rap

In [9]:
Lil_artists = Lil_data['artists']['items']

Lil_genres_list = []
for genres in Lil_artists:
    Lil_genres_list = genres["genres"] + Lil_genres_list
print(Lil_genres_list)


['crunk', 'dirty south rap', 'soca', 'freestyle', 'chicano rap', 'deep trap', 'jerk', 'chicano rap', 'hip pop', 'hip pop', 'juggalo', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'hip pop', 'pop rap', 'chicano rap', 'latin hip hop', 'crunk', 'dirty south rap', 'southern hip hop', 'dirty south rap', 'pop rap', 'southern hip hop', 'trap music']

Counting the genres.


In [10]:
Genre_list = [[x,Lil_genres_list.count(x)] for x in set(Lil_genres_list)]
print(Genre_list)


[['hip pop', 3], ['jerk', 1], ['chicano rap', 3], ['latin hip hop', 1], ['juggalo', 1], ['crunk', 3], ['deep trap', 1], ['trap music', 2], ['freestyle', 1], ['dirty south rap', 4], ['soca', 1], ['southern hip hop', 3], ['pop rap', 2]]

Sorting the genres by occurences.


In [11]:
sorted(Genre_list, key = lambda x: int(x[1]), reverse=True)

Sorted_by_occurences_Genre_list = sorted(Genre_list, key = lambda x: int(x[1]), reverse=True)
print("The most frequent genre of the musicians called Lil is", Sorted_by_occurences_Genre_list[0])


The most frequent genre of the musicians called Lil is ['dirty south rap', 4]

2 b) Edit your previous printout to also display a list of their genres in the format "GENRE_1, GENRE_2, GENRE_3". If there are no genres, print "No genres listed".


In [12]:
Lil_artists = Lil_data['artists']['items']
for artist in Lil_artists:
    if artist['genres'] == []:
        print(artist['name'], artist['popularity'], "No genres listed.")
    else:
        print(artist['name'], artist['popularity'], artist['genres'])


Lil Wayne 86 ['dirty south rap', 'pop rap', 'southern hip hop', 'trap music']
Lil Yachty 72 No genres listed.
Lil Uzi Vert 72 No genres listed.
Lil Dicky 68 No genres listed.
Boosie Badazz 67 No genres listed.
Lil Jon 72 ['crunk', 'dirty south rap', 'southern hip hop']
King Lil G 61 No genres listed.
Lil Durk 60 No genres listed.
Lil Jon & The East Side Boyz 60 No genres listed.
Lil Bibby 54 No genres listed.
G Herbo 53 No genres listed.
Lil Rob 50 ['chicano rap', 'latin hip hop']
Lil Reese 50 No genres listed.
Lil Keke 48 No genres listed.
Bow Wow 57 ['hip pop', 'pop rap']
Lil Scrappy 48 ['crunk', 'dirty south rap', 'southern hip hop', 'trap music']
Lil Wyte 50 ['juggalo']
Lil Blood 45 No genres listed.
Lil Snupe 45 No genres listed.
Lil Mama 45 ['hip pop']
Lil B 44 No genres listed.
Lil' Kim 62 ['hip pop']
Lil Cuete 40 ['chicano rap']
Lil Phat 39 No genres listed.
Lil Debbie 43 No genres listed.
Lil Twist 39 ['jerk']
Lil Trill 37 ['deep trap']
Lil Twon 38 No genres listed.
Lil AJ 37 No genres listed.
Lil Lonnie 37 No genres listed.
Lil Boom 35 No genres listed.
Lil Goofy 35 No genres listed.
Mr. Lil One 36 ['chicano rap']
Lil Haiti 36 No genres listed.
Lil Flash 38 No genres listed.
Lil Kesh 39 No genres listed.
Lil Cray 35 No genres listed.
Lil Silva 43 No genres listed.
Lil Rue 34 No genres listed.
Lil Eddie 41 No genres listed.
Lil Yase 33 No genres listed.
Lil Wayne, DJ Drama 35 No genres listed.
Lil Suzy 34 ['freestyle']
Lil Mouse 34 No genres listed.
Lil C 33 No genres listed.
Lil Rick 39 ['soca']
Lil June 32 No genres listed.
Lil E 34 No genres listed.
Lil Fate 34 No genres listed.
Lil' Flip 49 ['crunk', 'dirty south rap']

In [27]:
Lil_artists = Lil_data['artists']['items']

#Genres

all_genres = []

#The Loop

for artist in Lil_artists:
    #print("All Genres we have heard of:", all_genres)
    #print('Current artist has', artist['genres'])
    all_genres = all_genres + artist['genres']
    
print(all_genres)
all_genres.count('dirty south rap')
# your_list


['dirty south rap', 'pop rap', 'southern hip hop', 'trap music', 'crunk', 'dirty south rap', 'southern hip hop', 'chicano rap', 'latin hip hop', 'hip pop', 'pop rap', 'crunk', 'dirty south rap', 'southern hip hop', 'trap music', 'juggalo', 'hip pop', 'hip pop', 'chicano rap', 'jerk', 'deep trap', 'chicano rap', 'freestyle', 'soca', 'crunk', 'dirty south rap']
Out[27]:
4

In [28]:
#This shows duplicates
for genre in all_genres:
    genre_count = all_genres.count(genre)
    print(genre, "shows up", genre_count, "times.")


dirty south rap shows up 4 times.
pop rap shows up 2 times.
southern hip hop shows up 3 times.
trap music shows up 2 times.
crunk shows up 3 times.
dirty south rap shows up 4 times.
southern hip hop shows up 3 times.
chicano rap shows up 3 times.
latin hip hop shows up 1 times.
hip pop shows up 3 times.
pop rap shows up 2 times.
crunk shows up 3 times.
dirty south rap shows up 4 times.
southern hip hop shows up 3 times.
trap music shows up 2 times.
juggalo shows up 1 times.
hip pop shows up 3 times.
hip pop shows up 3 times.
chicano rap shows up 3 times.
jerk shows up 1 times.
deep trap shows up 1 times.
chicano rap shows up 3 times.
freestyle shows up 1 times.
soca shows up 1 times.
crunk shows up 3 times.
dirty south rap shows up 4 times.

In [29]:
#Unique list of all genres:
#Unique List = set(list_with_duplicates)
unique_genres = set(all_genres)
for genre in unique_genres:
    genre_count = all_genres.count(genre)
    print(genre, "shows up", genre_count, "times.")


hip pop shows up 3 times.
latin hip hop shows up 1 times.
chicano rap shows up 3 times.
jerk shows up 1 times.
juggalo shows up 1 times.
crunk shows up 3 times.
southern hip hop shows up 3 times.
deep trap shows up 1 times.
trap music shows up 2 times.
freestyle shows up 1 times.
dirty south rap shows up 4 times.
soca shows up 1 times.
pop rap shows up 2 times.

In [ ]:
#There is a library tha comes with Python called Collections
#Inside of this library is Counter

In [34]:
import collections

In [42]:
from collections import Counter

counts = Counter(all_genres)
counts.most_common(1)


Out[42]:
[('dirty south rap', 4)]

In [36]:
#
print(counts['crunk'])


3

In [60]:
from collections import Counter

counts = Collections.Counter(all_genres)
counts.most_common(1)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-60-fd5f811b34c9> in <module>()
      1 from collections import Counter
      2 
----> 3 counts = Collections.Counter(all_genres)
      4 counts.most_common(1)

NameError: name 'Collections' is not defined

how to automate all of the results


In [61]:
response = requests.get('https://api.spotify.com/v1/search?query=Lil&type=artist&limit=50&market=US')
small_data = response.json()

In [62]:
small_data['artists']
len(small_data['artists'])


Out[62]:
7

In [63]:
print("test")


test

In [ ]:

3 a) Use a for loop to determine who BESIDES Lil Wayne has the highest popularity rating.


In [64]:
for artist in Lil_artists: 
    if artist['popularity'] >= 72 and artist['name'] != 'Lil Wayne':
            print(artist['name'])


Lil Yachty
Lil Uzi Vert
Lil Jon

In [65]:
#Better solution:
most_popular_name = ""
most_popular_score = 0
for artist in Lil_artists:
    #print("Comparing", artist['popularity'], 'to', most_popular_score)
    if artist['popularity'] > most_popular_score:
        print("checking for Lil Wayne")
        if artist['name'] == 'Lil Wayne':
            print('go away')
        else:
        #The change you are keeping track of
        #a.k.a. what you are keeping track of
            print('not Lil Wayne, updating our notebook')
            most_popular_name = artist['name']
            most_popular_score = artist['popularity']
            
print(most_popular_name, most_popular_score)


checking for Lil Wayne
go away
checking for Lil Wayne
not Lil Wayne, updating our notebook
Lil Yachty 72

In [66]:
####### This doesn't work
#name = 'Lil Soma'
#target_score = 72
#1 INITIAL CONDITION
#second_best_artists = []
#second_best_artists = [Lil Yachty]

#Aggregation Problem
#When you're looping through a series of serious objects
#and sometimes you want to add one of those objects
#to a different list

#for artist in artists:
#    print('Looking at', artist['name'])
    #2 COndition
    #wehen we want someone on the list
#    if artist['popularity'] == 72:
#        print('!!! The artist is popularity is 72.')
#        second_best_artists.append(second_best_artists)

In [67]:
Lil_data['artists'].keys()


Out[67]:
dict_keys(['previous', 'items', 'total', 'href', 'offset', 'next', 'limit'])

3 b) Is it the same artist who has the largest number of followers?


In [68]:
type(artist['followers'])


Out[68]:
dict

In [69]:
artist['followers']


Out[69]:
{'href': None, 'total': 19889}

Creating a list of the popularity values, so we can sort them and say which one is the highest)


In [19]:
Lil_artists = Lil_data['artists']['items']
List_of_Followers = []
for artist in Lil_artists:
    List_of_Followers.append(artist['followers']['total'])
print(List_of_Followers)


[2623766, 37907, 55056, 224712, 220130, 256032, 64191, 134066, 17043, 44102, 51473, 35827, 23836, 18746, 118537, 27076, 31101, 5524, 33976, 21109, 224, 70218, 15577, 5331, 14521, 14832, 2123, 318, 897, 1330, 172, 1340, 4744, 679, 1763, 1660, 985, 9427, 3286, 1623, 1129, 12849, 5889, 16302, 1705, 1829, 1396, 130, 110, 19889]

Deciding which one is highest:


In [18]:
List_of_Followers.sort(reverse=True)
print(List_of_Followers)


[2622861, 255936, 224284, 219928, 133939, 118480, 70155, 64081, 54122, 51384, 44020, 37468, 35795, 33955, 31071, 27051, 23821, 21100, 19866, 18725, 17030, 16288, 15567, 14831, 14511, 12843, 9416, 5880, 5522, 5327, 4738, 3285, 2123, 1826, 1760, 1705, 1657, 1623, 1396, 1338, 1319, 1114, 983, 893, 668, 317, 217, 153, 130, 110]

In [19]:
Highest_Number_of_Followers = (List_of_Followers[0])

In [20]:
print(Highest_Number_of_Followers)


2622861

In [21]:
for artist in Lil_artists: 
    if artist['followers']['total'] > List_of_Followers[0] and artist['name'] != 'Lil Wayne':
        print(artist['name'], "has more followers than Lil Wayne.")
    else:
        print("Their are no artists with more followers that Lil Wayne.")
        break


Their are no artists with more followers that Lil Wayne.

4) Print a list of Lil's that are more popular than Lil' Kim.

Establishing how high Lil' Kim's popularity is. Would this be possible in one go?


In [19]:
for artist in Lil_artists: 
    if artist['name'] == "Lil' Kim":
        print(artist['popularity'])


62

In [20]:
for artist in Lil_artists: 
    if artist['popularity'] > 62:
        print(artist['name'], artist['popularity'])


Lil Wayne 86
Lil Yachty 72
Lil Uzi Vert 72
Lil Dicky 68
Boosie Badazz 67
Lil Jon 72

5) Pick two of your favorite Lils to fight it out, and use their IDs to print out their top tracks. Tip: You're going to be making two separate requests, be sure you DO NOT save them into the same variable.


In [21]:
for artist in Lil_artists:
    print(artist['name'], artist['id'])


Lil Wayne 55Aa2cqylxrFIXC767Z865
Lil Yachty 6icQOAFXDZKsumw3YXyusw
Lil Uzi Vert 4O15NlyKLIASxsJ0PrXPfz
Lil Dicky 1tqhsYv8yBBdwANFNzHtcr
Boosie Badazz 6z7xFFHxYkE9t8bwIF0Bvg
Lil Jon 7sfl4Xt5KmfyDs2T3SVSMK
King Lil G 6L3x3if9RVimruryD9LoFb
Lil Durk 3hcs9uc56yIGFCSy9leWe7
Lil Jon & The East Side Boyz 3ciRvbBIVz9fBoPbtSYq4x
Lil Bibby 4uSN8Y3kgFNVULUWsZEAVW
G Herbo 5QdEbQJ3ylBnc3gsIASAT5
Lil Rob 7B7TGqQe7QTVm2U6q8jzk1
Lil Reese 1bPxKZtCdjB1aj1csBJpdS
Lil Keke 1grI9x4Uzos1Asx8JmRW6T
Bow Wow 7352aRY2mqSxBZwzUb6LmA
Lil Scrappy 5einkgXXrjhfYCyac1FANB
Lil Wyte 21O7WwRkik43ErKppxDKJq
Lil Blood 74nSA5FdDOuuLw7Rn5JnuP
Lil Snupe 42FaEHFfyxTdZQ5W28dXnj
Lil Mama 5qK5bOC6wLtuLhG5KvU17c
Lil B 4dqh62yIzDBmrMeBOLiP5F
Lil' Kim 5tth2a3v0sWwV1C7bApBdX
Lil Cuete 1I5u5Umau1AgHl0ZbPL1oR
Lil Phat 3QnIBUOS4mUzs67rZ8r4c9
Lil Debbie 3FNZcjyqT7F5upP99JV0oN
Lil Twist 564gvOqSRcQoYAhaBpTiK2
Lil Trill 5EQERGi7ffHvHsv3bnqzBn
Lil Twon 5YZZbPdI7P7te3lW3dTpzK
Lil AJ 2jXwYLNnCxNavms4mc1DYM
Lil Lonnie 6zSBkdKFLKKggDtE3amfCk
Lil Goofy 3rWaFjgOi5mjQfllMfN3VI
Mr. Lil One 6tslWi0BXiDdtChermDzkU
Lil Flash 069qBEK34YGoX7nSIT74Eg
Lil Kesh 38XiDu0kK3Z5jdHUDqBzNT
Lil Haiti 4E9dumwOMLlTyXUp1i2WdI
Lil Silva 2Kv0ApBohrL213X9avMrEn
Lil Rue 4IFVaKBbEO8Qkurg6nmoc4
Lil Cray 43BqexhEx5NKF7VfeOYP9m
Lil Eddie 5CY0QKsbUBpQJIE2yycsYi
Lil Wayne, DJ Drama 65npPa1U4cgobX9wU7Jgpb
Lil Yase 4vIlHBnzWKbmWe8ZOkT1ZT
Lil Suzy 5HPsVk1MblCoa44WLJsQwN
Lil Mouse 1cEHxCgGlEgqBc91YOcAEQ
Lil C 69swdLSkKxCQBMYJ55O2mA
Lil Rick 1qKzKUnuQsjB83hBZffoq0
Lil Boom 1mmlWsyPJvvxMdabcGJjRn
Lil June 3GH3KD2078kLPpEkN1UN26
Lil E 0zn6yzsbWj3EPMgOTqfG5k
Lil Fate 6JUnsP7jmvYmdhbg7lTMQj
Lil' Flip 4Q5sPmM8j4SpMqL4UA1DtS

In [22]:
response = requests.get('https://api.spotify.com/v1/artists/5einkgXXrjhfYCyac1FANB/top-tracks?country=US')
Lil_Scrappy_data = response.json()
type(Lil_Scrappy_data)


Out[22]:
dict

In [23]:
response = requests.get('https://api.spotify.com/v1/artists/5qK5bOC6wLtuLhG5KvU17c/top-tracks?country=US')
Lil_Mama_data = response.json()
type(Lil_Mama_data)


Out[23]:
dict

In [24]:
Lil_Scrappy_data.keys()
Lil_Mama_data.keys()


Out[24]:
dict_keys(['tracks'])

In [25]:
type(Lil_Scrappy_data.keys())
type(Lil_Mama_data.keys())


Out[25]:
dict_keys

In [26]:
Scrappy_tracks = Lil_Scrappy_data['tracks']

for tracks in Scrappy_tracks:
    print(tracks['name'])


What U Gon' Do (feat. Lil Scrappy)
No Problem
Money In The Bank - Remix feat. Young Buck
Keep It 1000
Wait (The Whisper Song) Remix
Damn - Remix
Head Bussa - feat. Lil Jon
Like a Pimp - Remix
Livin' In The Projects
Oh Yeah - Work feat. Sean P. of YoungBloodZ and E-40

In [27]:
Mama_tracks = Lil_Mama_data['tracks']

for tracks in Mama_tracks:
    print(tracks['name'])


Lip Gloss
Shawty Get Loose
G-Slide (Tour Bus) - Radio Version
Dough Boy
Lip Gloss/ No Music - Main Version - clean
Shawty Get Loose
Hustler Girl
Bad As Me
Truly In Love
L.I.F.E.

6 Will the world explode if a musicians swears? Get an average popularity for their explicit songs vs. their non-explicit songs. How many minutes of explicit songs do they have? Non-explicit?

Number of Explicit Tracks for Lil Scrappy.


In [89]:
explicit_track_scrappy = 0
non_explicit_track_scrappy = 0
unknown_scrappy = 0
for tracks in Scrappy_tracks:
    if tracks['explicit'] == True:
        explicit_track_scrappy = explicit_track_scrappy + 1
    elif tracks['explicit'] == False:
        non_explicit_track_scrappy = non_explicit_track_scrappy + 1
    else:
        unknown_scrappy = unknown_scrappy + 1

explicit_track_pop_total = 0
non_explicit_track_pop_total = 0
for tracks in Scrappy_tracks:
    if tracks['explicit'] == True:
        explicit_track_pop_total = explicit_track_pop_total + tracks['popularity']
    elif tracks['explicit'] == False:
        non_explicit_track_pop_total = non_explicit_track_pop_total + tracks['popularity']

explicit_track_duration_total = 0
non_explicit_track_duration_total = 0
for tracks in Scrappy_tracks:
    if tracks['explicit'] == True:
        explicit_track_duration_total = explicit_track_duration_total + tracks['duration_ms']
    elif tracks['explicit'] == False:
        non_explicit_track_duration_total = non_explicit_track_duration_total + tracks['duration_ms']
    
print("The average rating of explicit songs by Lil Scrappy is", round(explicit_track_pop_total / explicit_track_scrappy), ".")
print("The average rating of non-explicit songs by Lil Scrappy is", round(non_explicit_track_pop_total / non_explicit_track_scrappy), ".")
print("The duration of explicit song material of Lil Scrappy is", round(explicit_track_duration_total / 1000), "minutes, and of non explicit material is", round(non_explicit_track_duration_total / 1000), "minutes.")


The average rating of explicit songs by Lil Scrappy is 41 .
The average rating of non-explicit songs by Lil Scrappy is 37 .
The duration of explicit song material of Lil Scrappy is 1809 minutes, and of non explicit material is 765 minutes.

And this is the same for Lil Mama:


In [90]:
explicit_track_Mama = 0
non_explicit_track_Mama = 0
unknown = 0
for tracks in Mama_tracks:
    if tracks['explicit'] == True:
        explicit_track_Mama = explicit_track_Mama + 1
    elif tracks['explicit'] == False:
        non_explicit_track_Mama = non_explicit_track_Mama + 1
    else:
        unknown = unknown + 1

explicit_track_pop_total_Mama = 0
non_explicit_track_pop_total_Mama = 0
for tracks in Mama_tracks:
    if tracks['explicit'] == True:
        explicit_track_pop_total_Mama = explicit_track_pop_total_Mama + tracks['popularity']
    elif tracks['explicit'] == False:
        non_explicit_track_pop_total_Mama = non_explicit_track_pop_total_Mama + tracks['popularity']
        
explicit_track_duration_total_Mama = 0
non_explicit_track_duration_total_Mama = 0
for tracks in Mama_tracks:
    if tracks['explicit'] == True:
        explicit_track_duration_total_Mama = explicit_track_duration_total_Mama + tracks['duration_ms']
    elif tracks['explicit'] == False:
        non_explicit_track_duration_total_Mama = non_explicit_track_duration_total_Mama + tracks['duration_ms']        
        
print("The average rating of explicit songs by Lil Mama is", round(explicit_track_pop_total_Mama / explicit_track_Mama), ".")
print("The average rating of non-explicit songs by Lil Mama is", round(non_explicit_track_pop_total_Mama / non_explicit_track_Mama), ".")
print("The duration of explicit song material of Lil Mama is", round(explicit_track_duration_total_Mama / 1000), "minutes, and of non explicit material is", round(non_explicit_track_duration_total_Mama / 1000), "minutes.")


The average rating of explicit songs by Lil Mama is 23 .
The average rating of non-explicit songs by Lil Mama is 32 .
The duration of explicit song material of Lil Mama is 526 minutes, and of non explicit material is 1769 minutes.

7 a) Since we're talking about Lils, what about Biggies? How many total "Biggie" artists are there? How many total "Lil"s? If you made 1 request every 5 seconds, how long would it take to download information on all the Lils vs the Biggies?


In [35]:
response = requests.get('https://api.spotify.com/v1/search?query=Biggie&type=artist&limit=50&market=US')
Biggie_data = response.json()

In [38]:
response = requests.get('https://api.spotify.com/v1/search?query=Lil&type=artist&limit=50&market=US')
Lil_data = response.json()

In [39]:
Biggie_artists = Biggie_data['artists']['total']
Lil_artists = Lil_data['artists']['total']
print("There are", Biggie_artists, "artists named Biggie on Spotify and", Lil_artists, "named Lil",)


There are 49 named Biggie on Spotify and 4501 called Lil

In [43]:
Total_Download_Time_Biggie = Biggie_artists / 50 * 5
Total_Download_Time_Lil = Lil_artists / 50 * 5
print("It would take", round(Total_Download_Time_Biggie), "seconds to download all the Biggie artists and", round(Total_Download_Time_Lil), "seconds to download the Lil artists." )


It would take 5 seconds to download all the Biggie artists and 450 seconds to download the Lil artists.

8) Out of the top 50 "Lil"s and the top 50 "Biggie"s, who is more popular on average?


In [68]:
Lil_artists_popularity = Lil_data['artists']['items']
popularity_total = 0
for popularity in Lil_artists_popularity:
    popularity_total = popularity_total + popularity['popularity']
print("The average rating for the top 50 artists called Lil is:", round(popularity_total / 50))


The average rating for the top 50 artists called Lil is: 46

In [70]:
Biggie_artists_popularity = Biggie_data['artists']['items']
Biggie_popularity_total = 0
for popularity2 in Biggie_artists_popularity:
    Biggie_popularity_total = Biggie_popularity_total + popularity2['popularity']
print("The average rating for the top 50 artists called Biggie is:", round(Biggie_popularity_total / 49) )


The average rating for the top 50 artists called Biggie is: 4

In [ ]:


In [65]:
Biggie_popularity = Biggie_data['artists']['items']
for artist in Biggie_popularity:
    print(artist['name'], artist['popularity'])


The Notorious B.I.G. 76
Biggie D 20
Biggie 23
Biggie Irie 15
Fabolous|Biggie|Busta|Nate Dogg 11
Biggie Smalls 13
Biggie Paul 17
Biggie the Kid 3
Alief Biggie 4
Papa Biggie 0
Mister Biggie 0
Biggie & Foldy 0
Biggie Bash 6
Dj Majah & Blaq Biggie Blaq 1
Biggie Tembo 0
Louis Biggie 0
Biggie Da Roxter 0
Biggie Dutch 0
Biggie Dutch feat. Marina Wilde 0
MC Biggie 0
Mr Biggie 0
Biggie & Anjay 0
Balder & Biggie 2
Poppa Biggie 0
Biggie Mic 0
Babie Biggie 0
Biggie Moe 0
MC Biggiedoy 0
Biggie Lu 0
Biggie Bandit 0
Biggie Babylon 0
Biggieballzh 0
1000 LBS (Biggie Irie 0
Biggie Brown 0
Biggie Vinkeloe 0
Biggie Sam 0
Crenshaw Biggie 0
Biggie Whit 0
Biggie Smiles 0
Biggie Nabwelela 0
Biggie Roggie Shirima 0
Wandung'u Biggie 0
Biggie Jackson 0
Kevy K Biggie 0
Andrew Biggie 0
Biggie Fab 0
Dj Biggie B 0
Biggie Smalls Featuring Grand Puba 0
Luke Biggie 0

In [ ]: